package com.etone.smartAudit.mapstruct;

import com.etone.smartAudit.domain.Tool;
import com.etone.smartAudit.domain.ToolCase;
import com.etone.smartAudit.vo.tool.ToolDetailVO;
import com.etone.smartAudit.vo.tool.ToolVO;
import com.etone.smartAudit.vo.toolCase.ToolCaseVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.NullValueCheckStrategy;

import java.util.List;

/**
 * @author: 蒋学伟
 * @create: 2020-07-08 15:20:40
 * @Description ToolMapStruct
 */
@Mapper(componentModel = "spring", imports = {com.etone.smartAudit.vo.FileVO.class, com.alibaba.fastjson.JSONArray.class, com.alibaba.fastjson.JSON.class}, nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS)
public interface ToolMapStruct {

    @Mappings({
            @Mapping(
                    target = "cover",
                    expression = "java(tool.getCover()==null||tool.getCover()==\"\"?null:JSON.parseObject(tool.getCover(),FileVO.class))"
            )
    })
    ToolVO getToolVO(Tool tool);

    List<ToolVO> getToolVO(List<Tool> tools);

    @Mappings({
            @Mapping(
                    target = "files",
                    expression = "java(toolCase.getFiles()==null||toolCase.getFiles()==\"\"?null:JSONArray.parseArray(toolCase.getFiles(),FileVO.class))"
            ),
            @Mapping(
                    target = "cover",
                    expression = "java(toolCase.getCover()==null||toolCase.getCover()==\"\"?null:JSON.parseObject(toolCase.getCover(),FileVO.class))"
            )
    })
    ToolCaseVO getToolCaseVO(ToolCase toolCase);

    List<ToolCaseVO> getToolCaseVO(List<ToolCase> toolCases);

    @Mappings({
            @Mapping(
                    target = "files",
                    expression = "java(tool.getFiles()==null||tool.getFiles()==\"\"?null:JSONArray.parseArray(tool.getFiles(),FileVO.class))"
            ),
            @Mapping(
                    target = "cover",
                    expression = "java(tool.getCover()==null||tool.getCover()==\"\"?null:JSON.parseObject(tool.getCover(),FileVO.class))"
            )
    })
    ToolDetailVO getToolDetailVO(Tool tool);
}
